﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class user_QueryNews1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnQuery_Click(object sender, EventArgs e)
    {
        string sql = "SELECT * FROM 通知 ";
        if (txtValue.Text.Trim().Length != 0)
            sql = sql + "WHERE 标题 like'%" + txtValue.Text + "%'";
        String strConnection = "Server=.;Database=keshe2;Integrated Security=SSPI";
        SqlConnection con = new SqlConnection(strConnection);
        con.Open();
        SqlConnection sqlcon = new SqlConnection(strConnection);
        sqlcon.Open();
        SqlCommand sqlcom = new SqlCommand(sql, sqlcon);
        SqlDataReader Dr = sqlcom.ExecuteReader();
        if (Dr.HasRows)
        {
            GridView1.DataSourceID = "sdsQueryNews";
            sdsQueryNews.SelectCommand = sql;
            sdsQueryNews.Select(DataSourceSelectArguments.Empty);
        }
        else
        {
            GridView1_empty();
        }
        Dr.Close();
        sqlcon.Close();
    }
    protected void GridView1_empty()
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("编号");
        dt.Columns.Add("标题");
        dt.Columns.Add("时间");     
        if (dt.Rows.Count == 0)
        {
            dt.Rows.Add(dt.NewRow());
            GridView1.DataSourceID = "";
            GridView1.DataSource = dt;
            GridView1.DataBind();
            int columnCount = dt.Columns.Count;
            GridView1.Rows[0].Cells.Clear();
            GridView1.Rows[0].Cells.Add(new TableCell());
            GridView1.Rows[0].Cells[0].ColumnSpan = columnCount;
            GridView1.Rows[0].Cells[0].Text = "暂无该通知记录！";
            GridView1.Rows[0].Cells[0].Style.Add("text-align", "center");
        }
    }
}